

package com.jackchong.ext

import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.jackchong.base.BaseView
import com.jackchong.base.JToast
import com.jackchong.utils.ToastUtils
import com.kongzue.dialog.util.DialogSettings
import com.kongzue.dialog.v3.CustomDialog
import com.kongzue.dialog.v3.MessageDialog
import com.kongzue.dialog.v3.TipDialog
import com.kongzue.dialog.v3.WaitDialog
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * author : jack(黄冲)
 * e-mail : 907755845@qq.com
 * create : 2020/7/28
 * desc   :
 */


fun toastE(msg: Any?) {
    ToastUtils.e(msg)
}

fun toastW(msg: Any?) {
    ToastUtils.w(msg)
}

fun toastD(msg: Any?) {
    ToastUtils.d(msg)
}

fun toastS(msg: Any?) {
    ToastUtils.success(msg)
}

fun toastTip(type: JToast.Type, content: CharSequence?) {
    JToast.show(type, content)
}


fun showLoading(activity: AppCompatActivity) {
    WaitDialog.show(activity, "").theme = DialogSettings.THEME.DARK
}

fun hideLoading() {
    WaitDialog.dismiss()
}

fun showTip(activity: AppCompatActivity, type: TipDialog.TYPE, message: String = "") {
    TipDialog.show(activity, message, type).theme = DialogSettings.THEME.DARK
    TipDialog.dismiss(2000)
}



fun AppCompatActivity.dialog(message: String, click: () -> Any, title: String = "提示", okButton: String = "确定", noButton: String = "取消") {
    MessageDialog.show(this, title, message, okButton, noButton).setOnOkButtonClickListener { baseDialog, v ->
        val results = click()
        if (results is Boolean){
             results
        }else
            false
    }
}



